package com.itheima.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.bean.Student;
import com.itheima.mapper.StudentMapper;
import com.itheima.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentServiceImpl implements StudentService{
    SqlSession sqlSession = MyBatisUtils.getSqlSession();
    StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
    @Override
    public List<Student> findAll() {
        //PageHelper.startPage(1,2);
        PageHelper.startPage(2,2);
        List<Student> list = mapper.findAll();
        PageInfo<Student> page = new PageInfo<>(list);
        System.out.println("总条数:"+page.getTotal());
        System.out.println("总页数:"+page.getPages());
        System.out.println("当前页:"+page.getPageNum());
        System.out.println("每页显示条数:"+page.getPageSize());
        System.out.println("上一页:"+page.getPrePage());
        System.out.println("下一页"+page.getNextPage());
        System.out.println("是否是第一页"+page.isIsFirstPage());
        System.out.println("是否是最后一页:"+page.isIsLastPage());
        System.out.println();
        sqlSession.close();
        return list;
    }

    @Override
    public List<Student> findByNameOrAge(String name, Integer age) {
        List<Student> list = mapper.findByNameOrAge(name, age);
        return list;
    }

    @Override
    public List<Student> findCondition(Student stu) {
        List<Student> list = mapper.findCondition(stu);
        return list;
    }

    @Override
    public List<Student> findByIds(List<Integer> list) {
        List<Student> students = mapper.findByIds(list);
        return students;
    }
}
